<template>
    <div>
        <div class="mainBox">
            <div style="display: flex;align-items: center;">
                <!-- <v-distpicker :province="selected.province" 
                    :city="selected.city"
                    @selected="onSelected" >
                </v-distpicker> -->
                <el-input v-model="schoolobj.itemname" placeholder="学校名称或编号" @change="schoolnamechange" clearable></el-input>
                <!-- <el-select v-model="schoolindex" placeholder="学校名称或编号">
                    <el-option
                    v-for="item in options"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                    </el-option>
                </el-select> -->
                <!-- <el-select v-model="examSubjectlist" placeholder="考试科目">
                    <el-option
                    v-for="item in options"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                    </el-option>
                </el-select> -->
            </div>
            <div>
                <!-- <el-button type="primary" @click="addnewschool">新增学校</el-button> -->
                <el-button type="primary" @click="copyexamclickbox">复用学校</el-button>
                <!-- <el-button type="primary" @click="batchuploadadd">批量新增</el-button> -->
                <!-- <el-button type="primary" style="background:#D54941;border-color:#D54941">批量删除</el-button> -->
            </div>
        </div>
        <div style="padding:15px;background:#fff;border-radius: 10px;">
            <el-table
                class="custom-table"
                ref="multipleTable"
                :data="stopexamlist"
                tooltip-effect="dark"
                style="width: 100%"
                stripe
                @selection-change="handleSelectionChange"
                :header-cell-style="{ background: '#D8E4F0', color: '#2A303B',fontWeight:'500' }">
                <el-table-column
                    type="selection"
                    width="55">
                </el-table-column>
                <el-table-column
                    label="序号">
                    <template slot-scope="scope">{{ scope.$index + 1 }}</template>
                </el-table-column>
                <el-table-column
                    prop="schoolnum"
                    label="学校代码">
                </el-table-column>
                <el-table-column
                    label="学校名称"
                    prop="schoolname">
                </el-table-column>
                <!-- <el-table-column
                    label="省市县"
                    prop="modelname">
                </el-table-column> -->
                <el-table-column
                    fixed="right"
                    label="操作"
                    align="center"
                    width="300">
                    <template slot-scope="scope">
                        <div style="display: flex;" class="scopednr">
                            <b @click="importStudent(scope.row)">批量导入学生</b>
                            <b @click="importTeacher(scope.row)">批量导入教师</b>
                            <b @click="modelclick(scope.row)">考试明细</b>
                            <!-- <b @click="editExamschool(scope.row)">编辑</b> -->
                            <!-- <b>删除</b> -->
                        </div>
                    </template>
                </el-table-column>
            </el-table>
            <div class="examfooter">
                <div class="examFootercontent">
                    <div>
                        <span class="totaldata">共<i>{{total?total:0}}</i>条数据</span>
                    </div>
                    <div>
                        <el-pagination
                            background
                            @current-change="handleCurrentChange"
                            :page-sizes="[20, 50,100]"
                            @size-change="handleSizeChange"
                            :page-size="pageSize"
                            layout="sizes, prev, pager, next"
                            :total="total">
                        </el-pagination>
                    </div>
                </div>
            </div>
        </div>
        <!-- 新增考试 -->
		<addSchool v-if="addSchoolshow" @addSchoolclick="addSchoolclick" :type="0"></addSchool>
        <!-- 创建复用考试 -->
		<examCopy v-if="examCopyIshow" @copyexamclick="copyemit" :type="1"></examCopy>
        <!-- 批量导入 -->
         <batchUpload v-if="uploadishow" @uploadclick="uploadclick" :importCon="importNumber"></batchUpload>
        <!-- 考试明细 -->
        <examMx v-if="examMxshow" @examMxclick="examMxclick" :examname="examname"></examMx>
    </div>
</template>

<script>
import addSchool from '../../../components/school/addschool.vue'
import examCopy from '../../../components/copyexam.vue'
import batchUpload from '../../../components/upload.vue'
import examMx from '../../../components/school/exammx.vue'
import { examschoolapi } from '../../../api/api.js'
import VDistpicker from 'v-distpicker'
export default {
    name: 'projectoverview',
    data () {
        return {
            stopexamlist:[],
            multipleSelection:[],
            addSchoolshow:false,
            schoolindex:'',
            examSubjectlist:'',
            selected: {
                province: '',
                city: '',
                area: ''
            },
            examCopyIshow:false,
            uploadishow:false,
            examMxshow:false,
            pageSize:50,
            currentPage:1,
            total:0,
            examcontent:{},
            options:[],
            schoolobj:{
                itemname:'',
                page:1,
                pagesize:20,
                navId:''
            },
            examname:'',
            importNumber:0,
        }
    },
    mounted() {
        this.examcontent = JSON.parse(sessionStorage.getItem('examContent'));
        this.examnavid = this.examcontent.nav5id
        this.getschoollist(this.examcontent.nav5id)
    },
    computed: {
        examId() {
            return this.$store.state.examId;
        }
    },
    watch: {
    	examId(newVal) {
            if (newVal) {
                this.examnavid = newVal;
                this.getschoollist(newVal);
                this.$store.commit('setExamId', ''); // 重置状态
            }
        }	
    },
    methods: {
        //批量导入学生
        importStudent(con){
            
            this.importNumber = {
                usertype:0,
                userGroup_id:con.gradeid
            }

            this.uploadishow = true
        },
        //批量导入教师
        importTeacher(con){
            this.importNumber = {
                usertype:1,
                userGroup_id:con.gradeid
            }
            this.uploadishow = true
        },
        //通过名称筛选学校
        schoolnamechange(val){
            this.schoolobj.itemname = val
            this.getschoollist(this.examnavid)
        },
        //获取学校列表
        getschoollist(examidnavid){
            // console.info('dddd0')
            // let obj={
            //     navId:this.examcontent.nav5id
            // }
            this.schoolobj.navId = examidnavid
            examschoolapi(this.schoolobj).then(res=>{
                console.info('res',res)
                if(res.code==0){
                	this.stopexamlist = res.obj.results 
                    this.total = res.obj.count
                }
            })
        },
        onSelected(){
				
			},
        handleSelectionChange(val) {
            this.multipleSelection = val;
        },
        //新增考试
        addnewschool(){
            this.addSchoolshow = true
        },
        addSchoolclick(){
            this.addSchoolshow = false
        },
        editExamschool(){
            this.addSchoolshow = true
        },
        copyexamclick(){
            this.examCopyIshow = false
        },
        copyexamclickbox(){
            this.examCopyIshow = true
        },
        batchuploadadd(){
            this.uploadishow = true
        },
        uploadclick(){
            this.uploadishow = false
        },
        // 考试明细
        examMxclick(){
            this.examMxshow = false
        },
        //考试明细
        modelclick(con){
            this.examMxshow = true
            this.examname = con
        },
        handleCurrentChange(val){
            this.schoolobj.page = val
            this.getschoollist()
        },
        handleSizeChange(val){
            this.schoolobj.pagesize = val
        },
        copyemit(){
            this.examCopyIshow = false
            this.getschoollist(this.examnavid)
        }
    },
    components: {
        addSchool,VDistpicker,examCopy,batchUpload,examMx,batchUpload
    }
}
</script>

<style scoped>
.mainBox{
    background:#fff;
    margin-bottom:15px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding:15px;
}
.mainBox >>> .el-button{
    background:#366EF4;
    border:solid 1px #366EF4;
    height:36px;
}
.mainBox >>> .el-select .el-input__inner{
	 width:150px; 
     margin-left:4px;
     border-radius: 10px;
     height:36px;
}
.mainBox >>> .el-input__icon{
    line-height:36px;
}
.mainBox >>> .distpicker-address-wrapper select{
    height:35px;
    line-height:35px;
    border-radius:10px;
    font-size:14px;
    color:#999;
    border:solid 1px #DCDFE6;
}
.custom-table {
	  width: 100%;
	  border: 1px solid rgba(216,228,240,0.34);
	  border-radius:10px;
	  border-right: none;
	  border-bottom:none;
	}
	
	/* 自定义表格内部元素的样式 */
	.custom-table >>> .el-table__header-wrapper th {
	  background-color: #E8F0FA;
	  height:42px;
	  padding:0;
	  text-align: center;
	  font-weight:normal
	}
	.custom-table >>> .el-table__row td {
	  height:42px;
	  padding:0;
	  text-align: center;
	  border-bottom:none;
	  border-right:solid 1px rgba(216,228,240,0.34);
	  font-size:14px;
	}
	.el-table .warning-row {
	    background: #ffffff;
	 }
	.el-table .success-row {
	    background: #D8E4F0;
	}
     .el-table .el-table__cell{
        padding:8px 0;
    }
    .scopednr b{
        display: inline-block;
        font-weight:normal;
        margin:0 8px;
        color:#165DFF;
        cursor: pointer;
    }
    .scopednr b:last-child{
        color:#D54941
    }
    .examfooter{
		width:100%;
		height:54px;
		left:0;
		bottom:0;
	}
	.examFootercontent{
		margin:0 auto;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
	.examFootercontent .totaldata{
		font-size:14px;
	}
	.examFootercontent .totaldata i{
		display: inline-block;
		color:#295CFF;
		font-style: normal;
		line-height:54px;
		padding:0 3px;
	}
</style>